/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package mii.dao.impl;

import java.util.List;
import javax.persistence.EntityManager;
import mii.dao.EngineerDAO;
import mii.ejb.entity.Engineer;

/**
 *
 * @author TEKNISI
 */
public class EngineerDAOImpl implements EngineerDAO {
    private EntityManager em;
    
    public EngineerDAOImpl(EntityManager em){
        this.em = em;
    }

    @Override
    public void insert(Engineer engineer) throws Exception {
        this.em.persist(engineer);
    }

    @Override
    public void update(Engineer engineer) throws Exception {
        this.em.merge(engineer);   }

    @Override
    public void delete(Engineer engineer) throws Exception {
        this.em.remove(engineer);   }

    @Override
    public Engineer getById(long id) throws Exception {
         return this.em.find(Engineer.class, id);
    }

    @Override
    public List<Engineer> getAll() throws Exception {
        return this.em.createQuery("SELECT e FROM Engineer e").getResultList();
    }

    @Override
    public Engineer getByKode(String kodeEng) throws Exception {
        return this.em.find(Engineer.class, kodeEng);
    }
    
}
